<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>开关灯案例</title>
    <style>
        .div1{
            position: absolute;
            width: 200px;
            height: 200px;
            margin: auto;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            background-color: red;
        }
    </style>
</head>
<body>
    <button>开灯</button>
    <button>关灯</button>
    <div class="div1"></div>
</body>
<script src="jquery-3.3.1.min.js"></script>
<script>
    $(function () {
       // 为按钮添加事件: 设置body背景色
       var btn2 = $('button')[1];
       btn2.onclick = function () {
           $('body').css('backgroundColor', 'grey');
       };
       var btn1 = $('button')[0];
       btn1.onclick = function () {
           $('body').css('backgroundColor', 'white');
       }
    });
</script>
</html>